package com.example.multiple.config;

import com.example.multiple.DataSourceBuilder;
import com.example.multiple.properties.DefaultDataSourceProperties;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

/**
 * @Author yanggld
 * @Date 2019/6/20-14:48
 * @Description
 */
@Component("defaultDataSourceBuilder")
public class DefaultDataSourceBuilder implements DataSourceBuilder {

	@Autowired
	private DefaultDataSourceProperties defaultDataSourceProperties;

	@Override
	public DataSource buildDataSource() {
		HikariDataSource dataSource = new HikariDataSource();
		dataSource.setDriverClassName(defaultDataSourceProperties.getDriverClassName());
		dataSource.setJdbcUrl(defaultDataSourceProperties.getUrl());
		dataSource.setUsername(defaultDataSourceProperties.getUsername());
		dataSource.setPassword(defaultDataSourceProperties.getPassword());
		return dataSource;
	}
}

